//
//  CigaretteParameterCell.m
//  FloatClouds
//
//  Created by 黄威 on 16/9/6.
//  Copyright © 2016年 黄威. All rights reserved.
//

#import "CigaretteParameterCell.h"
@interface CigaretteParameterCell ()
@property (nonatomic, strong) NSArray * arrayOfParameter;
@property (nonatomic,strong) UIPickerView *pick;
@end

@implementation CigaretteParameterCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
       
        
        self.arrayOfParameter = @[@"不限",@"0.1",@"0.2",@"0.3",@"0.4",@"0.5",@"0.6",@"0.7",@"0.8",@"0.9",@"1.0",@"1.1",@"1.2",@"1.3",@"1.4",@"1.5",@"1.6",@"1.7",@"1.8",@"1.9",@"2.0",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20"];
        
        self.pick = [[UIPickerView alloc] init];
        self.pick.dataSource = self;
        self.pick.delegate = self;
        self.label = [[UILabel alloc]init];
        [self addSubview:self.label];
        self.label2 = [[UILabel alloc]init];
        [self addSubview:self.label2];
        self.textfield = [[UITextField alloc]init];
        [self addSubview:self.textfield];
        self.textfield.borderStyle = UITextBorderStyleRoundedRect;
        self.textfield.inputView = self.pick;
        self.label2.text = @"mg";
        
    }
    
    return self;


}


- (void)layoutSubviews{

    [super layoutSubviews];
    
    self.label.frame =CGRectMake(0, 0, self.bounds.size.width * 0.4, self.bounds.size.height);
    
    self.textfield.frame = CGRectMake(self.bounds.size.width * 0.6 +3 , 3, self.bounds.size.width * 0.3 - 6 , self.bounds.size.height - 6);
    
    self.label2.frame = CGRectMake(self.bounds.size.width *0.9, 0, self.bounds.size.width * 0.1, self.bounds.size.height);


}


//代理方法
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.arrayOfParameter.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.arrayOfParameter[row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.textfield.text = self.arrayOfParameter[row];
    UIAlertView* alert = [[UIAlertView alloc]
                          initWithTitle:@"提示"
                          message:[NSString stringWithFormat:@"你选中的是：%@"
                                   , [ self.arrayOfParameter objectAtIndex:row]]
                          delegate:nil
                          cancelButtonTitle:@"确定"
                          otherButtonTitles:nil];
    [alert show];
    
    [self.textfield endEditing:YES];
    
}



@end
